//---------------------------------------------------------------------------
#ifndef vSImporterH
#define vSImporterH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
#include "WebHelp.h"
#include <Dialogs.hpp>
#include "OpenDirectory.h"
#include "vAPatienter.h"
#include "vADoublonRef.h"
#include "vASupprimer.h"
#include <ImgList.hpp>
#include "CCheckB.h"
#include "CComboBx.h"
#include <fstream>
using namespace std;
//---------------------------------------------------------------------------
#define ERREUR_SELECTION    "Veuillez sélectionner au moins une référence."
#define DLL_WHEDIT          "WHEdit.dll"
#define NEANT               "<Néant>"
//---------------------------------------------------------------------------
//Définition des requetes
/****************************************************************************/
//--> cbLien, cbRef, cbAucunEcart sont Checked
//--------------------------------------------
#define ALL_CHECKED   "(SELECT lower(refer.ref_nom) as 'refnom',lower(lien.lien_ref) as 'lienref' \
                        FROM refer left outer join lien on ((refer.log_code = lien.log_code) \
                                                        and (refer.ver_code = lien.ver_code) \
                                                        and (refer.ref_nom = lien.lien_ref)) \
                        where   (refer.log_code = %d) \
                            and (refer.ver_code = %d) )\
                        UNION \
                        (SELECT lower(refer.ref_nom),lower(lien.lien_ref) \
                         FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                        and (refer.ver_code = lien.ver_code) \
                                                        and (refer.ref_nom = lien.lien_ref)) \
                         where lien.log_code = %d and lien.ver_code = %d ) \
                         order by refnom"
/****************************************************************************/
//--> cbRef Checked
//-----------------
#define CBREF_CHECKED   "(SELECT distinct lower(refer.ref_nom),lower(lien.lien_ref) \
                          FROM refer left outer join lien on ((refer.log_code = lien.log_code) \
                                                         and (refer.ver_code = lien.ver_code)  \
                                                         and (refer.ref_nom = lien.lien_ref))  \
                          where refer.log_code = %d \
                            and refer.ver_code = %d \
                            and lien.lien_ref is null \
                          order by refer.ref_nom)"
/****************************************************************************/
//--> cbLien Checked
//------------------
#define CBLIEN_CHECHED   "(SELECT distinct lower(refer.ref_nom),lower(lien.lien_ref) \
                           FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                          and (refer.ver_code = lien.ver_code) \
                                                          and (refer.ref_nom = lien.lien_ref)) \
                           where lien.log_code = %d \
                             and lien.ver_code = %d \
                             and refer.ref_nom is null \
                           order by lien.lien_ref)"
/****************************************************************************/
//--> cbAucunEcart Checked
//------------------------
#define CBAUCUNECART_CHECHED    "(SELECT distinct lower(refer.ref_nom),lower(lien.lien_ref) \
                                  FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                                 and (refer.ver_code = lien.ver_code) \
                                                                 and (refer.ref_nom = lien.lien_ref)) \
                                  where lien.log_code = %d \
                                    and lien.ver_code = %d \
                                    and refer.ref_nom = lien.lien_ref \
                                  order by lien.lien_ref)"
/****************************************************************************/
//--> cbLien, cbRef sont Checked
//------------------------------
#define CBLIEN_CBREF_CHECHED    "(SELECT lower(refer.ref_nom) as 'refnom',lower(lien.lien_ref) as 'lienref' \
                                  FROM refer left outer join lien on ((refer.log_code=lien.log_code) \
                                                                 and (refer.ver_code = lien.ver_code) \
                                                                 and (refer.ref_nom = lien.lien_ref)) \
                                  where refer.log_code = %d \
                                    and refer.ver_code = %d \
                                    and lien.lien_ref is null \
                                  order by refer.ref_nom, lien.lien_ref) \
                                  UNION \
                                  (SELECT lower(refer.ref_nom),lower(lien.lien_ref) \
                                  FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                                 and (refer.ver_code =lien.ver_code) \
                                                                 and (refer.ref_nom = lien.lien_ref)) \
                                  where lien.log_code = %d \
                                    and lien.ver_code = %d \
                                    and refer.ref_nom is null) \
                                  order by refnom"
/****************************************************************************/
//--> cbRef, cbAucunEcart sont Checked
//------------------------------------
#define CBREF_CBAUCUNECART_CHECHED  "(SELECT lower(refer.ref_nom) as 'refnom',lower(lien.lien_ref) as 'lienref' \
                                      FROM refer left outer join lien on ((refer.log_code=lien.log_code) \
                                                                     and (refer.ver_code = lien.ver_code) \
                                                                     and (refer.ref_nom = lien.lien_ref)) \
                                      where refer.log_code = %d \
                                        and refer.ver_code = %d \
                                        and lien.lien_ref is null \
                                      order by refer.ref_nom, lien.lien_ref) \
                                      UNION \
                                     (SELECT lower(refer.ref_nom),lower(lien.lien_ref) \
                                     FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                                    and (refer.ver_code =lien.ver_code) \
                                                                    and (refer.ref_nom = lien.lien_ref)) \
                                     where  lien.log_code = %d \
                                        and lien.ver_code = %d \
                                        and refer.ref_nom is not null) \
                                     order by refnom"
/****************************************************************************/
//--> cbLien, cbAucunEcart sont Checked
//-------------------------------------
#define CBLIEN_CBAUCUNECART_CHECHED "(SELECT lower(refer.ref_nom) as 'refnom',lower(lien.lien_ref) as 'lienref' \
                                      FROM refer left outer join lien on ((refer.log_code=lien.log_code) \
                                                                     and (refer.ver_code = lien.ver_code) \
                                                                     and (refer.ref_nom = lien.lien_ref)) \
                                      where refer.log_code = %d \
                                        and refer.ver_code = %d \
                                        and lien.lien_ref is not null \
                                      order by refer.ref_nom, lien.lien_ref) \
                                      UNION \
                                      (SELECT lower(refer.ref_nom),lower(lien.lien_ref) \
                                      FROM lien left outer join refer on ((refer.log_code = lien.log_code) \
                                                                     and (refer.ver_code =lien.ver_code) \
                                                                     and (refer.ref_nom = lien.lien_ref)) \
                                      where lien.log_code = %d \
                                        and lien.ver_code = %d \
                                        and refer.ref_nom is null) \
                                      order by refnom"
/****************************************************************************/
//---------------------------------------------------------------------------
class TfImport : public TForm
{
    __published:	// Composants gérés par l'EDI
        TPanel *Panel1;
        TPanel *Panel2;
        TLabel *Label1;
        TLabel *Label2;
        COpenDirectory *codSelect;
        TSpeedButton *bCreer;
        TSpeedButton *bSupprimer;
        TSpeedButton *bbSelect;
        TSpeedButton *bbUnSelect;
        TSpeedButton *bbLire;
        TSpeedButton *bbQuitter;
        TSpeedButton *bbImprimer;
        TSpeedButton *bbApercu;
        TImageList *ImgRef;
        TPanel *pFiltre;
        CCheckBox *cbLien;
        CCheckBox *cbRef;
        CCheckBox *cbAucunEcart;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TListView *lvListe;
        TSpeedButton *sbRazFiltre;
        TLabel *lRefWebHelp;
        CComboBox *cbLogiciel;
        CComboBox *cbVersion;
        void __fastcall cbLogicielChange(TObject *Sender);
        void __fastcall bbLireClick(TObject *Sender);
        void __fastcall cbVersionChange(TObject *Sender);
        void __fastcall bCreerClick(TObject *Sender);
        void __fastcall bbApercuClick(TObject *Sender);
        void __fastcall bbImprimerClick(TObject *Sender);
        void __fastcall bSupprimerClick(TObject *Sender);
        void __fastcall bbSelectClick(TObject *Sender);
        void __fastcall bbUnSelectClick(TObject *Sender);
        void __fastcall lvListeCustomDrawSubItem(TCustomListView *Sender,
        TListItem *Item, int SubItem, TCustomDrawState State,
        bool &DefaultDraw);
        void __fastcall bbQuitterClick(TObject *Sender);
        void __fastcall lvListeColumnClick(TObject *Sender,
          TListColumn *Column);
        void __fastcall lvListeCompare(TObject *Sender, TListItem *Item1,
          TListItem *Item2, int Data, int &Compare);
        void __fastcall cbLienClick(TObject *Sender);
        void __fastcall cbRefClick(TObject *Sender);
        void __fastcall cbAucunEcartClick(TObject *Sender);
        void __fastcall sbRazFiltreClick(TObject *Sender);

    private:	// Déclarations utilisateur

        TStringList * m_lRef;
        TStringList * m_lObj;
        TStringList * m_lEcran;

        int nColumnToSort;
        int nLastColumn;
        bool bAscToDesc;

    private:
        void __fastcall GetLogiciel( char * cLog );
        void __fastcall GetVersion( char * cVer );
        bool       __fastcall GetAdresse(const AnsiString &asRef);
        bool       __fastcall VerifierListe( void );
        AnsiString __fastcall ChoisirRequete( void );

    public:		// Déclarations utilisateur
        __fastcall TfImport(const int &nLogiciel, const int &nVersion, TComponent* Owner);
        __fastcall ~TfImport();
        void __fastcall RechercherDfm( const AnsiString &asRepertoire );
        void __fastcall TraiterDFM( const AnsiString &asFichier, const AnsiString &asNomFichier );
        void __fastcall GetObject(char * cLigne, char * cObj);
        void __fastcall GetRef(char * cLigne, char * cRefer);
        bool __fastcall VerifierDoublon( void );
        void __fastcall LogVerSelectionner(const int &nLogiciel, const int &nVersion);
        void __fastcall ViderTableLien( void );
        void __fastcall Edition(bool bVisu);
        void __fastcall Afficher();
};
//---------------------------------------------------------------------------
#endif
